/* 
 返回带x位小数的数字
 1. 不传x参数，默认返回两位0的小数
 @return {Float}
 */
export const fn_decimal = (num, x=0) => {
	num = Number(num)
	if (x == 0) {
		num = parseInt(num).toFixed(2)
	}else {
		num = num.toFixed(x)
	}
	return num
}

/**
 * 跳转小程序
 * @return {void}
 */
export const fn_toMiniProgram = (that, params={}) => {
	uni.navigateToMiniProgram({
		appId: 'appid',
		path: 'pages/index/index?id=335',
		fail: () => {
			that.$toast('打开小程序失败')
		},
		...params
	})
}

/**
 * 处理number
 * 例如：1000000 => 1,000,000    10000.00 => 10,000.00
 * @return {String}
 */
export const fn_count = (val) => {
	let result  = []
	let counter = 0;
	let arr = String(val).split('.')
	let num = arr[0]
	for (var i = num.length - 1; i >= 0; i--) {
	counter++
	result.unshift(num[i])
	if (!(counter % 3) && i != 0) { 
		result.unshift(',')
	 }
	}
	return arr[1] ? (result.join('') + '.' + arr[1]) : result.join('');
}